home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InterruptedIOException;
-
- class NetPipedInputStream extends InputStream {
- boolean closed = true;
- boolean connbroken = true;
- Thread readSide;
- Thread writeSide;
- private byte[] buffer = new byte[1024];
- // $FF: renamed from: in int
- int field_0 = -1;
- int out;
-
- public NetPipedInputStream(NetPipedOutputStream src) throws IOException {
- this.connect(src);
- }
-
- public NetPipedInputStream() {
- }
-
- public void connect(NetPipedOutputStream src) throws IOException {
- src.connect(this);
- }
-
- synchronized void receive(int b) throws IOException {
- int waitValue = 5;
- this.writeSide = Thread.currentThread();
-
- while(this.field_0 == this.out) {
- if (this.readSide != null && !this.readSide.isAlive()) {
- throw new IOException("Pipe broken");
- }
-
- this.notifyAll();
- if (this.connbroken) {
- throw new IOException("Lost connection to server");
- }
-
- try {
- if (waitValue < 640) {
- waitValue *= 2;
- }
-
- this.wait((long)waitValue);
- } catch (InterruptedException var3) {
- throw new InterruptedIOException();
- }
- }
-
- if (this.field_0 < 0) {
- this.field_0 = 0;
- this.out = 0;
- }
-
- this.buffer[this.field_0++] = (byte)(b & 255);
- if (this.field_0 >= this.buffer.length) {
- this.field_0 = 0;
- }
-
- }
-
- synchronized void receive(byte[] b, int off, int len) throws IOException {
- while(true) {
- --len;
- if (len < 0) {
- return;
- }
-
- this.receive(b[off++]);
- }
- }
-
- synchronized void receivedLast() {
- this.closed = true;
- this.notifyAll();
- }
-
- synchronized void connBroken() {
- this.connbroken = true;
- this.notify();
- }
-
- public synchronized int read() throws IOException {
- int trials = 2;
- int waitValue = 5;
-
- while(this.field_0 < 0) {
- this.readSide = Thread.currentThread();
- if (this.writeSide != null && !this.writeSide.isAlive()) {
- --trials;
- if (trials < 0) {
- throw new IOException("Pipe broken");
- }
- }
-
- if (this.closed) {
- return -1;
- }
-
- if (this.connbroken) {
- throw new IOException("Lost connection to server");
- }
-
- this.notifyAll();
-
- try {
- if (waitValue < 640) {
- waitValue *= 2;
- }
-
- this.wait((long)waitValue);
- } catch (InterruptedException var4) {
- throw new InterruptedIOException();
- }
- }
-
- int ret = this.buffer[this.out++] & 255;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
-
- return ret;
- }
-
- public synchronized int read(byte[] b, int off, int len) throws IOException {
- if (len <= 0) {
- return 0;
- } else {
- int c = this.read();
- if (c < 0) {
- return -1;
- } else {
- b[off] = (byte)c;
- int rlen = 1;
-
- while(this.field_0 >= 0) {
- --len;
- if (len <= 0) {
- break;
- }
-
- b[off + rlen] = this.buffer[this.out++];
- ++rlen;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
- }
-
- return rlen;
- }
- }
- }
-
- public void close() throws IOException {
- this.field_0 = -1;
- this.closed = true;
- }
- }
-